﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BDCS.Model;
using BDCS.BLL;

namespace BDCS.UI
{
    public partial class AlterSubBuildTypes : Form
    {
        #region 成员字段
        private Model.T_SubBuildTyppes modelSubBuildType;
        private BLL.T_SubBuildTyppes bllSubBuildType;
        private int sbtid;
        private int btid;
        private string sbtName;
        private string sbtNameTwo;
        private string sbtDescribe;
        private string sbtDescribeTwo;
        #endregion
        #region 构造函数
        public AlterSubBuildTypes()
        {
            InitializeComponent();
        }
        public AlterSubBuildTypes(Model.T_SubBuildTyppes subBuildType)
        {
            this.modelSubBuildType = subBuildType;
            InitializeComponent();
        }
        #endregion
        #region 成员事件
        private void AlterSubBuildTypes_Load(object sender, EventArgs e)
        {
            this.btid = Convert.ToInt32(this.modelSubBuildType.BTID);
            this.sbtid = this.modelSubBuildType.SBTID;
            this.txtSubBuildTypes.Text = this.modelSubBuildType.SBTName;
            this.txtBuildTypeDescribe.Text = this.modelSubBuildType.SBTypeDescribe;
            this.sbtName = this.modelSubBuildType.SBTName;
            this.sbtDescribe = this.modelSubBuildType.SBTypeDescribe;
            this.sbtNameTwo = this.modelSubBuildType.SBTName;
            this.sbtDescribeTwo = this.modelSubBuildType.SBTypeDescribe;
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            modelSubBuildType = new Model.T_SubBuildTyppes();
            bllSubBuildType = new BLL.T_SubBuildTyppes();
            modelSubBuildType.BTID = this.btid;
            modelSubBuildType.SBTID = this.sbtid;
            modelSubBuildType.SBTName = this.txtSubBuildTypes.Text.Trim();
            modelSubBuildType.SBTypeDescribe = this.txtBuildTypeDescribe.Text.Trim();
            if (this.txtSubBuildTypes.Text.Trim() != this.sbtName || this.txtBuildTypeDescribe.Text.Trim() != this.sbtDescribe)
            {
                try
                {
                    if (bllSubBuildType.Update(modelSubBuildType) == true)
                    {
                        this.sbtName = txtSubBuildTypes.Text.Trim();
                        this.sbtDescribe = txtBuildTypeDescribe.Text.Trim();
                        BDCS.Common.TreeViewState.IsChangedAttribute = true;
                        MessageBox.Show("修改成功！");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有修改任何内容，不需要提交！");
            }
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.txtSubBuildTypes.Text = this.sbtNameTwo;
            this.txtBuildTypeDescribe.Text = this.sbtDescribeTwo;
            if (sbtName != sbtNameTwo || sbtDescribe != sbtDescribeTwo)
            {
                modelSubBuildType = new Model.T_SubBuildTyppes();
                modelSubBuildType.SBTID = this.sbtid;
                modelSubBuildType.BTID = this.btid;
                modelSubBuildType.SBTName = sbtNameTwo;
                modelSubBuildType.SBTypeDescribe = sbtDescribeTwo;
                bllSubBuildType = new BLL.T_SubBuildTyppes();
                try
                {
                    bllSubBuildType.Update(modelSubBuildType);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
        #endregion
    }
}
